package com.hefeng.example.controller;

import com.hefeng.example.controller.entiy.ParamEntity;
import com.hefeng.example.service.CustomerManualWorkOrderService;
import com.hefeng.example.service.SichuangResultService;
import com.hefeng.example.service.UserInfoService;
import com.hefeng.common.core.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Slf4j
@RestController
@RequestMapping("/DeviceInfo")
@Api(tags = "设备详情接口")
public class DeviceInfoController {
    @Autowired
    private CustomerManualWorkOrderService customerManualWorkOrderService;
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private SichuangResultService sichuangResultService;

    /**
     * 根据工单id获取设备信息
     *
     * @param id
     * @return
     */
    @PostMapping("/details")
    public AjaxResult slelct(Integer id) {
        return AjaxResult.success(customerManualWorkOrderService.WorkDeviceInfo(id));
    }

    /**
     * 逾期或者处理中获取工单详情
     *
     * @param
     * @return
     */
    @PostMapping(value = "/WorkDetails", produces = "application/json;charset=UTF-8")
    public AjaxResult Details(@RequestBody ParamEntity param) {
        String userType = param.getUserType();
        //判断用户类型 01维保  02四川合丰
        switch (userType) {
            case "01":
                Map<String, Object> map = new HashMap<>();
                List<Map> list2 = userInfoService.select(param.getDeviceId());
                map.put("userInfo", list2);
                List<Map> list3 = customerManualWorkOrderService.WorkOrderDetails(param.getId());
                map.put("orderInfo", list3);
                return AjaxResult.success(map);
            case "02":
                Map<String, Object> map02 = new HashMap<>();
                List<Map> list4 = sichuangResultService.WorkOrderDetails(param.getId());
                map02.put("orderInfo", list4);
                return AjaxResult.success(map02);

        }
        return AjaxResult.success("获取成功");
    }

    /**
     * 转派工单详情
     *
     * @param param
     * @return
     */
    @PostMapping(value = "/turnWork", produces = "application/json;charset=UTF-8")
    public AjaxResult turn(@RequestBody ParamEntity param) {
        Map<String, Object> map = new HashMap<>();
        List<Map> list4 = userInfoService.select(param.getDeviceId());
        map.put("userInfo", list4);
        List<Map> list5 = customerManualWorkOrderService.turnWork(param.getId());
        map.put("orderInfo", list5);

        return AjaxResult.success(map);
    }

    /**
     * 已完成工单详情
     */
    @PostMapping(value = "/finishWork", produces = "application/json;charset=UTF-8")
    public AjaxResult turnWork(@RequestBody ParamEntity param) {
        String userType = param.getUserType();
        //判断用户类型 01维保  02四川合丰
        switch (userType) {
            case "01":
                Map<String, Object> map = new HashMap<>();
                List<Map> list6 = userInfoService.select(param.getDeviceId());
                map.put("userInfo", list6);
                List<Map> list7 = customerManualWorkOrderService.finishWork(param.getId());
                map.put("photoInfo", list7);
                List<Map> list8 = customerManualWorkOrderService.WorkOrderDetails(param.getId());
                map.put("orderInfo", list8);
                return AjaxResult.success(map);
            case "02":
                Map<String, Object> map02 = new HashMap<>();
                List<Map> list02 = sichuangResultService.finishWorkXQ(param.getId());
                map02.put("photoInfo", list02);
                List<Map> list002 = sichuangResultService.WorkOrderDetails(param.getId());
                map02.put("orderInfo", list002);
                return AjaxResult.success(map02);
        }
        return AjaxResult.success("获取成功");
    }
}